﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using PowersourceUIToolkit;
using UCL.Powersource;
using System.Collections.ObjectModel;

namespace UCL.Powersource.Analysis
{
    [DataContract]
    public class StatisticCollectionWithResults : InitializedLifeCycleBase, IStatisticCollectionWithResults 
    {

        [DataMember]
        private List<IStatistic> _ItemsInternalList;

        private ReadOnlyCollection<IStatistic> _Items;
        public ReadOnlyCollection<IStatistic> Items 
        {
            get { if (!IsInitialized || IsDisposed) return null; else return _Items; }
        }

        public void MergeResultsFromStatisticManager(IStatisticManager ism)
        {
                if (_ItemsInternalList!=null) _ItemsInternalList.Clear();
                _ItemsInternalList=new List<IStatistic>();
                _ItemsInternalList.AddRange(ism.AvailableStatistics.Values);
        }

        public void MergeResultsFromStatisticManager()
        {
            var ism=IoC.Get<IStatisticManager>();
            MergeResultsFromStatisticManager(ism);
        }

        protected override bool OnInitializing()
        {
            _Items = new ReadOnlyCollection<IStatistic>(_ItemsInternalList);
            return true;
            
        }

        protected override void OnDisposing()
        {
            return;
        }

    }
}
